jQuery(function(){
	if($("#isSuitably1").val() == 1){
		$("#isSuitably").val("是");
	}
	else{
		$("#isSuitably").val("否");
	}
	if($("#isArrive1").val() == 1){
		$("#isArrive").val("是");
	}
	else{
		$("#isArrive").val("否");
	}
	var date = new Date();
	if(jQuery("#setDate1").val() != ""){
		date =jQuery("#setDate1").val();
	}
	var date1 = new Date();
	if(jQuery("#serviceDate1").val() != ""){
		date1 =jQuery("#serviceDate1").val();
	}
	jQuery("#sendDate").val(moment(jQuery("#sendDate1").val()).format("YYYY/MM/DD"));
	jQuery("#setDate").val(moment(date).format("YYYY-MM-DD"));
	jQuery("#setDate2").val(moment(date).format("YYYY-MM-DD"));
	jQuery("#serviceDate").val(moment(date1).format("YYYY-MM-DD"));
	jQuery("#qualityGuarantee").val($("#qualityGuarantee1").val());
	
	//////保存运单号////
	jQuery('.saveNum').on('click',function(){
		var ticketId = $("#ticketId").val();
		var waybillNum=$("#waybillNum").val();
		var url = window.rootPath + '/api/afterSaleTickets/'+ticketId;
    	var d={
    			"waybillNum":waybillNum
		}
		jQuery.ajax({
			url : encodeURI(url),
			type : 'patch',
			data : JSON.stringify(d),
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function() {
				message("运单号已经保存");
			}
		});
		
		
	})
	//tab2保存按钮
	jQuery('.saveTab2Btn').on("click", function() {
		var tab2Id = $("#tab2Id").val();
		var d= 
		{
				"recordCode":$("#recordCode").val(),
				"deviceState":$("#deviceState").val(),
				"isGuarantee":$("#qualityGuarantee").val(),
				"dutyBlong":$("#dutyBlong").val(),
				"questionDescription":$("#questionDescription").val(),
				"reasonAnalyse":$("#reasonAnalyse").val(),
				"solvePlan":$("#solvePlan").val(),
				"memo":$("#memo").val()
		}
		var url = window.rootPath + '/api/afterSaleTicketBacks/' + tab2Id;
		jQuery.ajax({
			url : encodeURI(url),
			type : 'patch',
			data : JSON.stringify(d),
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function() {
				$.springLemonDialog({
	   		         content: '跟踪记录已保存！',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
			}

		});
	});
	//tab3保存按钮
	jQuery('.saveTab3Btn').on("click", function() {
		var tab3Id = $("#tab3Id").val();
		var d= 
		{
				"repairCode":$("#repairCode").val(),"setDate":$("#setDate").val(),
				"outCode":$("#outCode").val(),"seatCode":$("#seatCode").val(),
				"inPressure":$("#inPressure").val(),"outPressure":$("#outPressure").val(),
				"lube":$("#lube").val(),"caseTemp":$("#caseTemp").val(),
				"bearingTemp":$("#bearingTemp").val(),"pumpValue":$("#pumpValue").val(),
				"balanceValue":$("#balanceValue").val(),"motorCurrent":$("#motorCurrent").val(),
				"inPressure1":$("#inPressure1").val(),"outPressure1":$("#outPressure1").val(),
				"lube1":$("#lube1").val(),"caseTemp1":$("#caseTemp1").val(),
				"bearingTemp1":$("#bearingTemp1").val(),"pumpValue1":$("#pumpValue1").val(),
				"balanceValue1":$("#balanceValue1").val(),"motorCurrent1":$("#motorCurrent1").val(),
				"outputTap":$("#outputTap").val(),"minTap":$("#minTap").val(),
				"inputTap":$("#inputTap").val(),"stopTap":$("#stopTap").val(),
				"minLevelTap":$("#minLevelTap").val(),"abraseState":$("#abraseState").val(),
				"horizontalCenter":$("#horizontalCenter").val(),"verticalCenter":$("#verticalCenter").val(),
				"opening":$("#opening").val(),"axialSize":$("#axialSize").val(),
				"horizontalCenter1":$("#horizontalCenter1").val(),"verticalCenter1":$("#verticalCenter1").val(),
				"opening1":$("#opening1").val(),"axialSize1":$("#axialSize1").val(),
				"questionDealSuggest":$("#questionDealSuggest").val(),"servicePerson":$("#servicePerson").val(),
				"serviceDate":$("#serviceDate").val(),"userAdvise":$("#userAdvise").val(),
				"memo":$("#memo").val()
		}
		var url = window.rootPath + '/api/afterSaleTicketAdvices/' + tab3Id;
		jQuery.ajax({
			url : encodeURI(url),
			type : 'patch',
			data : JSON.stringify(d),
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function() {
				$.springLemonDialog({
	   		         content: '跟踪记录已保存！',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
			}

		});
	});
	//服务单跟踪情况保存
	jQuery('.tranceSave').on("click", function() {
		if (jQuery("#activeTypeForm") && !jQuery("#activeTypeForm").Validform({
			tiptype : 3,
			showAllError : true
		}).check(false)) {return;}
		jQuery(".tranceSave").attr("disabled","disabled");
		var d= 
		{
				"activeType":$("#activeType").val(),
				"afterSaleTicket":{"id":$("#ticketId").val()},
				"afterSaleOutHouse":{"id":$("#outServiceId").val()},
				"user":{"id":$("#userId").val()},
				"memo":$("#tranceMemo").val()
		}
		var url = window.rootPath + '/ui/afterSaleOutHouse/tranceSave' ;
		jQuery.ajax({
			url : encodeURI(url),
			type : 'post',
			data : JSON.stringify(d),
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function() {
				$("#activeType").val("");
				$("#tranceMemo").val("");
				serverData.ticketId=$("#ticketId").val();
				var d={
						"outState":2//2 处理中
				}
				var url = window.rootPath + '/api/afterSaleOutHouses/'+$("#outServiceId").val();
				jQuery.ajax({
					url : encodeURI(url),
					type : 'patch',
					data : JSON.stringify(d),
					dataType : 'json',
					contentType : 'application/json;charset=utf-8',
					success : function() {
						jQuery(".tranceSave").removeAttr("disabled");
						serverTable.draw();
						message('跟踪记录已保存!');
					}
				});	
			}
		});
	});
	jQuery('.delete-btn').on("click",function(){
		var selects=getSelect("#ticketTranceTable",1);
    	var url = window.rootPath + "/ui/afterSaleOutHouse/delete";
 	   delSelect(selects,url,serverTable)
	});
	
	var outId=$("#outServiceId").val()
	var serverData = {};
	    serverData.outId=outId;
	var serverTable;
	jQuery(document).ready(function(){
		serverTable = jQuery('#ticketTranceTable').DataTable({
			    "serverSide": true,
	            "ordering": false,
	            "ajax": {
	                "dataType": "json",
	                "type": "get",
	                "cache": false,
	                "url":window.rootPath+ '/ui/afterSaleOutHouse/getTrancePage',
	                "data": function (d) {
	                    return $.extend({}, d, serverData);
	                }
	            },
	            "iDisplayLength": 5,
											columns : [
													{
														data : null,
														defaultContent : ""
													},
													{
													    data:null,
													    render: function(data, type, full, meta){
													    	var operate ='<input type="checkbox" class="checkchild">';
													    	var id=data.id;
													    	return operate;
																	
															}
											           },
													{
														data: "activeType",
													},
													
													{
														data : 'createTime',
														render : function(data,
																type, full,
																meta) {
															if (data) {
																return moment(data).format("YYYY-MM-DD");
															}
														}
													},
													{
														data : 'memo'
													}],
											"drawCallback" : function(oSettings) {
												var k = 0;
												var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;

												for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
													$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
													k++;
												}

												
											}
										});
						
					});
	   ///////列表中的全选
    $("#checkAll").click(function(){
    	var check = $(this).prop("checked");
        $(".checkchild").prop("checked", check);
	});
})